package ui.panels.primary.second;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;

import org.apache.log4j.Logger;

import Data.ConfigurationParameters;
import auxiliary.AuxiliaryClass;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;

import ui.flowManager.FlowManager;
import ui.flowManager.FlowManagerImpl;
import ui.flowManager.expirimentProperties.ExperimentProperties;
import ui.panels.Panel;
import ui.panels.PanelTypes;
import ui.panels.PanelTypes.PanelType;
import ui.panels.commands.NextCommand;
import ui.panels.commands.ReadFromFileCommand;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * 
 * @author vladimir && alon
 * 
 *
 */
public class SecondPanel extends Panel{

	private static 		ArrayList<String> observationList = null;
	
	Logger log = Logger.getLogger(this.getClass());

	private JButton 				enterButoon;
	
	private JTextField 				jTextField1;
	
	private JComboBox 				observationDrop;
	private JTextField 				nameField;
	private JTextField 				repeatsField;
	
	private JLabel 					nameLabel;
	private JLabel 					turnsLabel;
	private JLabel 					repeatsLabel;
	private JLabel 					observationLabel;
	
	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
		
	public SecondPanel(HashMap<String, String> map)
	{
		super();
	}
	
	
	public SecondPanel() {
		// TODO Auto-generated constructor stub
	}


	@Override
	public PanelType getPanelType() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void show(final ExperimentProperties props) {

		 
		log.debug("started show in second panel - Number Of Games");
			
		 try
		 {
			 AnchorLayout thisLayout = new AnchorLayout();
			 setLayout(thisLayout);
			 setPreferredSize(new Dimension(720, 480));
			 {
				 observationDrop = new JComboBox();
				 this.add(observationDrop, new AnchorConstraint(803, 567, 871, 325, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				 observationDrop.setPreferredSize(new java.awt.Dimension(174, 33));
			 }

			 //the label for text
			 
				 turnsLabel = new JLabel("Enter Number Of Turns");
				this.add(turnsLabel, new AnchorConstraint(288, 609, 388, 289, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				turnsLabel.setFont(new Font("Serif", Font.ITALIC, 20));
				turnsLabel.setPreferredSize(new java.awt.Dimension(230, 48)); 

				jTextField1 = new JTextField();	
				jTextField1.setText("");
				Font font = new Font(Font.MONOSPACED, Font.TRUETYPE_FONT, 20);
				jTextField1.setFont(font);
				this.add(jTextField1, new AnchorConstraint(388, 596, 488, 289, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));			
				jTextField1.setPreferredSize(new java.awt.Dimension(221, 48));

				enterButoon = new JButton("Enter");
				Font buttonfont = new Font(Font.MONOSPACED, Font.TRUETYPE_FONT, 20);
				enterButoon.setFont(buttonfont);
				this.add(enterButoon, new AnchorConstraint(317, 776, 468, 700, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_REL));
				enterButoon.setPreferredSize(new java.awt.Dimension(100, 129));

				 nameLabel = new JLabel();
				 this.add(nameLabel, new AnchorConstraint(88, 609, 188, 289, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				 nameLabel.setText("Enter The Experiment Name");
				 nameLabel.setPreferredSize(new java.awt.Dimension(230, 48));
				 nameLabel.setFont(new Font("Serif",Font.ITALIC,20));

				 nameField = new JTextField();
				 this.add(nameField, new AnchorConstraint(176, 596, 276, 289, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				 nameField.setFont(font);
				 nameField.setText("");
				 nameField.setPreferredSize(new java.awt.Dimension(221, 48));
			
			 {
				 observationLabel = new JLabel("Observation", JLabel.CENTER);
				 this.add(observationLabel, new AnchorConstraint(703, 596, 803, 314, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				 observationLabel.setFont(new Font("Serif",Font.ITALIC,20));
				 observationLabel.setPreferredSize(new java.awt.Dimension(203, 48));
			 }
			 
				 repeatsLabel = new JLabel();
				 this.add(repeatsLabel, new AnchorConstraint(501, 610, 601, 289, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				 repeatsLabel.setText("Enter Number Of Repeats");
				 repeatsLabel.setFont(new Font("Serif",Font.ITALIC,20));
				 repeatsLabel.setPreferredSize(new java.awt.Dimension(231, 48));
			 
				 repeatsField = new JTextField();
				 this.add(repeatsField, new AnchorConstraint(596, 596, 696, 289, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				 repeatsField.setFont(font);
				 repeatsField.setText("");
				 repeatsField.setPreferredSize(new java.awt.Dimension(221,48));
			 

			 //  ***add listeners ***
			 enterButoon.addActionListener(new SecondPanelListener(this, props));
			 //call to set the drop
			 SetComponentsOptions();
		 }
		//end of try
		 catch (Exception e) {
				log.debug(e.toString());
		}	
	}
	//end of show

	private void SetComponentsOptions()
	{
		//case there is distributionList
		if(observationList != null)
		{
			for(int i = 0; i < observationList.size(); ++i){
				observationDrop.addItem(observationList.get(i));
			}	
		}
	}
	
	@Override
	public void setFromPropertiesConfig(HashMap<String, String> map) {
		
		observationList = new ArrayList<String>();
		String initString=readFromProps(map.get(ConfigurationParameters.Observation.OBSERVATION));
		String[] values=initString.split(",");	
		for(int i = 0; i < values.length; ++i)
		{
			observationList.add(values[i]);
		}
	}

	public JTextField getjTextField1() {
		return jTextField1;
	}


	public JTextField getNameField() {
		return nameField;
	}

	public JComboBox getObservationDrop() {
		return observationDrop;
	}


	public JTextField getRepeatsField() {
		return repeatsField;
	}
	
}
